/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */

package quest.abyssal_splinter;

import gameserver.model.gameobjects.Npc;
import gameserver.model.gameobjects.player.Player;
import gameserver.quest.handlers.QuestHandler;
import gameserver.quest.model.QuestCookie;
import gameserver.quest.model.QuestState;
import gameserver.quest.model.QuestStatus;
import gameserver.services.QuestService;

public class _30357LaizesPanoplyGloves extends QuestHandler
{
	private final static int questId = 30357;
	
	public _30357LaizesPanoplyGloves()
	{
		super(questId);
	}
	
	@Override
	public boolean onDialogEvent(QuestCookie env)
	{
		final Player player = env.getPlayer();
		int targetId = 0;
		
		if (env.getVisibleObject() instanceof Npc)
			targetId = ((Npc) env.getVisibleObject()).getNpcId();
		
		QuestState qs = player.getQuestStateList().getQuestState(questId);
		
		if(qs == null || qs.getStatus() == QuestStatus.NONE) 
		{
			if(targetId == 278152) //Darkhum
			{
				if(env.getDialogId() == 26)
				{
					return sendQuestDialog(env, 1011);
				}
				else
					return defaultQuestStartDialog(env);
			}
		}
		
		if (qs == null)
			return false;
			
		if(qs == null || qs.getStatus() == QuestStatus.COMPLETE) 
		{
			if(targetId == 278152) //Darkhum
			{
				if(env.getDialogId() == 26)
				{
					return sendQuestDialog(env, 1011);
				}
				else
					return defaultQuestStartDialog(env);
			}
		}
		
		if (qs.getStatus() == QuestStatus.START)
		{
			switch (targetId)
			{
				case 278152: //Darkhum
					switch (env.getDialogId())
					{
						case 26:
							return sendQuestDialog(env, 2375);
						case 2034:
							return sendQuestDialog(env, 2034);
						case 34:
							//Collect Aether Marble (1)
							if (QuestService.collectItemCheck(env, true))
							{
								player.getInventory().removeFromBagByItemId(182209831, 1);
								qs.setStatus(QuestStatus.REWARD);
								updateQuestStatus(env);
								return sendQuestDialog(env, 5);
							}
							else
							{
								return sendQuestDialog(env, 2716);
							}
					}
					break;
				default:
					return defaultQuestStartDialog(env);
			}
		}
		else if (qs.getStatus() == QuestStatus.REWARD)
		{
			if(targetId == 278152) //Darkhum
				return defaultQuestEndDialog(env);
		}
		return false;
	}
	
	@Override
	public boolean onLvlUpEvent(QuestCookie env)
	{
		Player player = env.getPlayer();
		QuestState qs = player.getQuestStateList().getQuestState(questId);
		boolean lvlCheck = QuestService.checkLevelRequirement(questId, player.getCommonData().getLevel());
		
		if(qs != null || !lvlCheck)
			return false;
		
		QuestService.startQuest(env, QuestStatus.START);
		return true;
	}
	
	@Override
	public void register()
	{
		qe.setNpcQuestData(278152).addOnQuestStart(questId); //Darkhum
		qe.setNpcQuestData(278152).addOnTalkEvent(questId); //Darkhum
	}
}
